/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: 05.06.12
 * Time: 15:05
 * To change this template use File | Settings | File Templates.
 */
package zakladki.AS3 {
import flash.events.Event;

import mx.core.FlexGlobals;
import mx.core.UIComponent;

public class ToolTipHelper {

    private var uiComponent:UIComponent;

    private var switcher:int = 0;
    private var posXa:Number;
    private var posYa:Number;
    private var posXb:Number;
    private var posYb:Number;
    private var help:String = "";

    private var mainApp:Fossilminator = FlexGlobals.topLevelApplication as Fossilminator;

    public function ToolTipHelper(uiComp:UIComponent) {
        this.uiComponent = uiComp;
        this.posXa = uiComp.mouseX;
        this.posYa = uiComp.mouseY;
        this.posXb = uiComp.mouseX;
        this.posYb = uiComp.mouseY;
    }

    public function setHelp(set_string:String):void
    {	help = set_string;
        if(help != ""){
            uiComponent.addEventListener(Event.ENTER_FRAME, checkMovement);
        }
        else {
            uiComponent.removeEventListener(Event.ENTER_FRAME, checkMovement);
        }
    }

    private function checkMovement(e:Event):void {
        if(help != ""){
            if (switcher == 0){
                posXa = uiComponent.mouseX;
                posYa = uiComponent.mouseY;
                switcher = 1;
            }
            else{
                posXb = uiComponent.mouseX;
                posYb = uiComponent.mouseY;
                switcher = 0;
            }

            if (posXa == posXb && posYa == posYb){
                mainApp.startToolTip(help);
            }
            else {
                mainApp.destroyBigTip();
            }
        }
    }
}
}
